package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC397 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int integerReplacement(int n) {
            if (n == Integer.MAX_VALUE) return 32;
            if (n <= 3) return n - 1;
            if (n % 2 == 0) return integerReplacement(n / 2) + 1;
            else return Math.min(integerReplacement(n - 1), integerReplacement(n + 1)) + 1;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.integerReplacement(2147483647));
    }

    public static void main(String[] args) throws Exception {
        LC397 an = new LC397();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
